package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
//    注入service对象
    @Autowired
    private UserService userService;
    @RequestMapping("/register")
    public Result register(String username, String password){
        //查询用户
        User user = userService.finByUserName(username);
        if(user==null){
            //没有占用
            //注册
            userService.register(username,password);
            return Result.success();
        }else{
            return Result.error("用户名已存在");
        }
        //注册
    }

}
